<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<!-- <script type="text/javascript" src="/codebase/dhtmlxform.js" /> -->
<!-- <script type="text/javascript" src="/codebase/dhtmlxeditor.js" />   -->
 <script type="text/javascript" src="/codebase/dhtmlx.js" /> 
<style>
div#simpleLog {
	height: 200px;
	font-family: Roboto, Arial, Helvetica;
	font-size: 14px;
	color: #404040;
	overflow: auto;
}

div#div_label1 {
	font-family: Roboto, Arial, Helvetica;
	font-size: 14px;
	color: #404040;
	overflow: auto;
	padding-left: 50px;
}

div#div_label2 {
	font-family: Roboto, Arial, Helvetica;
	font-size: 14px;
	color: #404040;
	overflow: auto;
	padding-left: 50px;
}
</style>
<script>
/*<![CDATA[*/
	var myForm;
	var dhxWins2 ;
	var customCss = {
		video_bitrate : "validate_magenta",
		video_codec : "validate_orange"
	};
	
	function doOnLoad() {
		//alert("onload req assign");
		if (myForm) {
			myForm.unload();
			myForm = null;
		}
		//var get_assign_req_id=document.getElementsByTagName("assign_req_id").text;
		var v=document.getElementById("assign_req_id").innerHTML;
		
		//alert("get_assign_req_id :"+v);
		/*
		formStructure = null;
		formStructure = [ 
							{type: "fieldset", label: "需求信息", inputWidth: 340, list:[
									{type:"block",list:[		
							     		 {type : "input",name : "req_bill_no",label : "分配需求",labelWidth:"70",position:"label-left", disabled:"true"}
							      ]}
							]}
						];
		*/
		myForm = new dhtmlXForm("form_req_assign_details");
		//myForm.loadStruct(formStructure);
		//myForm.loadStruct("/common/testmanager/req_assign_detail.xml");
		//myForm.loadStruct("/req/req_assign_detail_onload?id="+v, callback);
		myForm.loadStruct("/req/req_assign_detail_onload?id="+v);
		//attachment
		/* if (form_attach) {
			form_attach.unload();
			form_attach = null;
		}
		form_attach = new dhtmlXForm("div_attacher"); */
		//form_attach.loadStruct("/common/testmanager/attachment.xml");
		
		
		// button setup
		/*formStructure=null;
		formStructure=[
		               {type:"button",name:"assign_btn1",value:"分配需求"},
		               {type:"newcolumn"},
		               {type:"button",name:"assign_btn2",value:"退回"}
			               ];
		if (my_form2) {
			my_form2.unload();
			my_form2 = null;
		}		
		my_form2=new dhtmlXForm("form_btn");
		my_form2.loadStruct(formStructure);
		*/
		
		myForm.attachEvent("onValidateError", function (name, value, result){
			var tmp_label=myForm.getItemLabel(name);	
			if(tmp_label=="需求分析工作量"){
				alert("【需求分析工作量】字段，请输入数字,小数位只有一位，且只能为5或0! \n 录入值为"+value);
				myForm.enableItem("assign_btn1");
			}
			else{
				  alert("校验【"+tmp_label+"】 值为【"+value+ "】 ， 请更正");
				  myForm.enableItem("assign_btn1");
			}	   
					
		  
		});
		
		myForm.attachEvent("onButtonClick", function(name) {		
			
			if(name=="assign_btn1"){
				//alert("分配需求assign_btn1");	
				var v=document.getElementById("assign_req_id").innerHTML;
				myForm.setItemValue("req_id", v);
				myForm.disableItem("assign_btn1");
				
				var s2=myForm.getSelect("req_analyst");
				
				for (var i=0;i<s2.options.length;i++)
				{
					s2.options[i].selected=true
				}		
				
				var s3=myForm.getSelect("req_supervisor");
				
				if(s3!=null){
					for (var i=0;i<s3.options.length;i++)
					{
						s3.options[i].selected=true
					}	
				}				
				this.send("/req/req_assign_save",callback);
				//myForm.enableItem(name);
				//this.send("/req/req_assign_save?req_id="+v,callback);
				
			}
			
			
			if(name=="assign_btn2"){
				//alert("需求退回");
				createWindow();
				
			}
			
			
			 if (name == "add2" || name == "remove2") {
					change_req_analyst(name=="add2");
				};	 
			
			if (name == "add3" || name == "remove3") {
					change_req_supervisor(name=="add3");
				};	
				
			var btn_tmp=name.split("_");
			if(btn_tmp[0]=="download"){
				//myForm.send("/req/req_assign_detail_page_download_att?att_id="+btn_tmp[1], "get", downloadcallback,true);
				window.location.href = "/req/req_assign_detail_page_download_att?att_id="+btn_tmp[1];
			}
	
	});	
		
			myForm.attachEvent("onUploadFile", function(realName, serverName) {
				atts_add_gropid(arguments[2].att_gropid);
				atts_add_ids(arguments[2].att_ids);
				//var mu=myForm.getUploader("myFiles");
			});
			
			myForm.attachEvent("onUploadComplete",function(count){
				//logEvent("<br></br>onUploadComplete "+count+" file"+(count>1?"s were":" was")+" uploaded");
				alert("上传"+count+"个文件完成.");
			});
			
			myForm.attachEvent("onUploadFail",function(realName){
				//logEvent("onUploadFail, file: "+realName);
				alert("上传文件"+realName+"失败，请检查上传文件大小");
			});
			
		
				
/* 		myForm.attachEvent("onAfterValidate", function (status){
		     //your code here
			myForm.save("/req/req_assign_save",callback);
			alert("分配需求成功");	 */
	
		
	}
	
	function atts_add_ids(ids) {
		var txt="";
		//var get_input_att_ids=myForm.getInput("att_id");
		//txt=get_input_att_ids.value;
		txt=myForm.getItemValue("att_id");
		if (txt==""){
			//get_input_att_ids.value=ids;
			myForm.setItemValue("att_id",ids);
		}else{
			//get_input_att_group.value=txt+","+ids;
			myForm.setItemValue("att_id",txt+","+ids);
		}				
		//att_group.hide=true;
		//atts.hidden=true;
	}
	
	function atts_add_gropid(g_id) {
		var txt="";
		//var get_input_att_group=myForm.getInput("att_group_id");
		//txt=get_input_att_group.value;
		txt=myForm.getItemValue("att_group_id");
		if (txt==""){
			//get_input_att_group.value=g_id;
			myForm.setItemValue("att_group_id",g_id);
		}else{
			//get_input_att_group.value=txt+","+g_id;
			myForm.setItemValue("att_group_id",txt+","+g_id);
		}				
		//att_group.hidden=true;
		//atts.hide=true;
	}
	function createWindow() {
		//alert("open_createWindow");
		var p = 0;		
		var id = "return_req_window";
		//
		var w = 700;
		var h = 200;
		var x = 100;
		var y = 700;
		
		//
		dhxWins2=new dhtmlXWindows();
		dhxWins2.createWindow(id, x, y, w, h);
		//dhxWins2.window(id).center();
		dhxWins2.window(id).setText("需求退回");
		
		dhxWins2.window(id).denyPark();
		dhxWins2.window(id).button("park").hide();
		var v=document.getElementById("assign_req_id").innerHTML;
		
		dhxWins2.window(id).attachURL("/req/req_reject?req_id="+v);
		
		dhxWins2.attachEvent("onClose", function(win){
		    
		    var ifr = dhxWins2.window(id).getFrame();		    
		    var win_value = ifr.contentWindow.document.getElementById("is_close_parent_window").innerHTML;
		    if(win_value=="true"){
		    	parent.dhxWins.window("req_assign_window").close();
		    }
		    	
		    return true;
		    
		});
		
	
	}
	function callback(){
		
		
		if (arguments[1]=="true"){
			alert("分配需求成功");
		
			parent.dhxWins.window("req_assign_window").close();
		//	var myWins = new dhtmlxWindows();
			//myWins.window("req_assign_window").close();
		}else{
			alert("分配需求失败！callback : "+arguments[1]);
			myForm.enableItem(name);
		}
	}
	function downloadcallback(){
		
	}
		
	
	function doCustomCss(name, value, res) {
		logEvent("onValidate " + (res ? "Success" : "Error")
				+ " called, item '" + name + "'<br/>");
	}
	function check_workload(data) {
		//alert(data);
		//var check_value=myForm.getItemValue("req_workload");
		
		var reg = new RegExp("^[0-9]+(.[05]{1})?$");  
		data=data*1;
		var t_check_value=data.toFixed(1);
			  if(!reg.test(t_check_value)){  
			     //   alert("【需求分析工作量】字段，请输入数字,小数位只有一位，且只能为5或0!录入值为"+check_value);
			        var r=false;
			        return(r);
			    }else{
			    	return(true);
			    }
		}
	
	function change_req_analyst(block) {
		
		var ida = (block?"req_analyst":"req_analyst_all");
		var idb = (block?"req_analyst_all":"req_analyst");
		
		var sa = myForm.getSelect(ida);
		var sb = myForm.getSelect(idb);
		
		var t = myForm.getItemValue(ida);
		if (t.length == 0) return;
		eval("var k={"+t.join(":true,")+":true};");
		
		var w = 0;
		var ind = -1;
		while (w < sa.options.length) {
			if (k[sa.options[w].value]) {
				sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
				sa.options.remove(w);
				ind = w;
			} else {
				w++;
			}
		}
		
		if (sa.options.length > 0 && ind >= 0) {
			if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
		}
		
	}

	function change_req_supervisor(block) {
		
		var ida = (block?"req_supervisor":"req_supervisor_all");
		var idb = (block?"req_supervisor_all":"req_supervisor");
		
		var sa = myForm.getSelect(ida);
		var sb = myForm.getSelect(idb);
		
		var t = myForm.getItemValue(ida);
		if (t.length == 0) return;
		eval("var k={"+t.join(":true,")+":true};");
		
		var w = 0;
		var ind = -1;
		while (w < sa.options.length) {
			if (k[sa.options[w].value]) {
				sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
				sa.options.remove(w);
				ind = w;
			} else {
				w++;
			}
		}
		
		if (sa.options.length > 0 && ind >= 0) {
			if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
		}
		
	}
	/*]]>*/	
</script>
</head>
<body onload="doOnLoad();">
	<div id="assign_req_id" name="assign_req_id" th:text="${test_v}"
		style="display: none;"></div>
	<table>
		<tr>
			<td>
				<div id="form_req_assign_details"></div>
			</td>
		</tr>
	</table>
	<table>

		<tr>
			<td>
				<div id="editorObj1" style="padding-left: 50px;"></div>
			</td>
		</tr>
	</table>

	<table>

		<tr>
			<td>
				<div id="editorObj2" style="padding-left: 50px;"></div>
			</td>
		</tr>
	</table>
	<table>
		<tr>
			<td>
				<div id="div_attacher"></div>
			</td>
		</tr>
	</table>
	<table>
		<tr>
			<td>
				<div id="form_btn" style="padding-left: 50px;"></div>
			</td>
		</tr>
	</table>
</body>
</html>